#include "DHT11Sensor.h"
#include "../../application/App.h"

DHT11Sensor::DHT11Sensor() : _dht(DHT11_PIN, DHT11) {
}

void DHT11Sensor::begin() {
    _dht.begin();
    _initialized = true;
    Serial.println("[DHT11] 初始化成功");
}

float DHT11Sensor::readTemperature() {
    if (!_initialized) return NAN;
    return _dht.readTemperature();
}

float DHT11Sensor::readHumidity() {
    if (!_initialized) return NAN;
    return _dht.readHumidity();
}

bool DHT11Sensor::readData(float &temperature, float &humidity) {
    if (!_initialized) return false;
    
    humidity = _dht.readHumidity();
    temperature = _dht.readTemperature();
    
    return !(isnan(humidity) || isnan(temperature));
}